
package com.agritech.path;

import com.agritech.environment.EnvironmentData;
import com.agritech.strategy.PathPlanningStrategy;

/**
 * 路径规划上下文类
 * 策略模式的上下文类，负责与具体策略交互
 */
public class PathPlanningContext {
    private PathPlanningStrategy strategy;
    
    public PathPlanningContext() {
        // 默认策略为null，需要显式设置
    }
    
    public PathPlanningContext(PathPlanningStrategy strategy) {
        this.strategy = strategy;
    }
    
    /**
     * 设置路径规划策略
     * @param strategy 路径规划策略
     */
    public void setStrategy(PathPlanningStrategy strategy) {
        this.strategy = strategy;
        System.out.println("已切换路径规划策略为: " + strategy.getStrategyName());
    }
    
    /**
     * 执行路径规划
     * @param environmentData 环境数据
     * @param startX 起始点X坐标
     * @param startY 起始点Y坐标
     * @param endX 目标点X坐标
     * @param endY 目标点Y坐标
     * @param obstacles 障碍物坐标数组
     * @return 路径规划结果
     */
    public PathPlan planPath(EnvironmentData environmentData, 
                            double startX, double startY, 
                            double endX, double endY, 
                            double[][] obstacles) {
        if (strategy == null) {
            throw new IllegalStateException("未设置路径规划策略，请先设置策略");
        }
        
        return strategy.calculatePath(environmentData, startX, startY, endX, endY, obstacles);
    }
    
    /**
     * 获取当前策略
     * @return 当前使用的路径规划策略
     */
    public PathPlanningStrategy getStrategy() {
        return strategy;
    }
}